package com.agmte.api.config;

import com.agmte.api.common.crud.tableAutoCreate.PgTableSynchronizer;
import com.agmte.api.config.filter.Knife4ApiScanner;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.sql.Connection;

@Slf4j
@Component("StartupRunnerA1f7856e")
public class StartupRunner implements CommandLineRunner {
    @Resource
    private JdbcTemplate jdbcTemplate;
    @Resource
    private Knife4ApiScanner scanner;

    @Override
    public void run(String... args) throws Exception {
        Connection connection = jdbcTemplate.getDataSource().getConnection();

        // 创建同步器实例
        PgTableSynchronizer synchronizer = new PgTableSynchronizer(connection, "com.agmte.api");
        synchronizer.syncTable();

        log.info("扫描表格数量：{}", PgTableSynchronizer.getTables().size());

        // 接口初始化未knife4
        scanner.apiScanner();

//        log.info(
//                "\n"+
//                "┏━╸╻ ╻┏━┓╺┳╸┏━┓┏┳┓   ┏━┓┏━┓╻\n" +
//                "┃  ┃ ┃┗━┓ ┃ ┃ ┃┃┃┃   ┣━┫┣━┛┃\n" +
//                "┗━╸┗━┛┗━┛ ╹ ┗━┛╹ ╹   ╹ ╹╹  ╹\n"+
//                "custom api start success    \n "
//        );

        log.info(
                "\n"+
                "                       __                                                    \n" +
                        "                      /\\ \\__                                           __    \n" +
                        "  ___   __  __    ____\\ \\ ,_\\   ___     ___ ___          __     _____ /\\_\\   \n" +
                        " /'___\\/\\ \\/\\ \\  /',__\\\\ \\ \\/  / __`\\ /' __` __`\\      /'__`\\  /\\ '__`\\/\\ \\  \n" +
                        "/\\ \\__/\\ \\ \\_\\ \\/\\__, `\\\\ \\ \\_/\\ \\L\\ \\/\\ \\/\\ \\/\\ \\    /\\ \\L\\.\\_\\ \\ \\L\\ \\ \\ \\ \n" +
                        "\\ \\____\\\\ \\____/\\/\\____/ \\ \\__\\ \\____/\\ \\_\\ \\_\\ \\_\\   \\ \\__/.\\_\\\\ \\ ,__/\\ \\_\\\n" +
                        " \\/____/ \\/___/  \\/___/   \\/__/\\/___/  \\/_/\\/_/\\/_/    \\/__/\\/_/ \\ \\ \\/  \\/_/\n" +
                        "                                                                  \\ \\_\\      \n" +
                        "                                                                   \\/_/      \n"+
                        "                               custom api start success    \n "
        );


    }
}
